package com.bh.config;

import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

/**
 * @author Wang
 * @version 1.0
 * @date 2022/6/8 15:35
 */
@Configuration
public class RestConfig {

    /**
     * 向容器注入工具类
     * @return
     */
    @Bean
    @LoadBalanced
    public RestTemplate restTemplate(){
        HttpComponentsClientHttpRequestFactory factory=new HttpComponentsClientHttpRequestFactory();
        factory.setConnectTimeout(1);
        factory.setReadTimeout(1);
        return new RestTemplate(factory);
    }
}
